package chapter04.d1_fileio.demo1;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: jack_yang
 * @Date: 2024/5/8
 * @Description: addition and subtraction
 */
public class FileWriteTest {
    public static void main(String[] args) throws IOException {
        File file = new File("D:\\test.txt");
        FileWriter fileWriter = new FileWriter(file);
        try{
//            chapter04.d1_fileio.demo1.Student student = new chapter04.d1_fileio.demo1.Student("张三", 1);
            List<Student> studentList = Student.getStudentList();
            FileWriter fw = new FileWriter(file);
            for(Student s:studentList){
                fileWriter.write(s.toString());
            }

            fileWriter.flush();
            System.out.println("写入成功");
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            //                fileWriter.close();
            System.out.println("关闭流");
        }

    }
}
